package com.ztorn.services.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ztorn.dtos.PickDetailRespDTO;
import com.ztorn.dtos.PickRespDTO;
import com.ztorn.mapper.InvMapper;
import com.ztorn.mapper.OutMapper;
import com.ztorn.model.MypktHdr;
import com.ztorn.model.MyunitInv;
import com.ztorn.services.OutService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OutServiceImpl extends ServiceImpl<OutMapper, MypktHdr> implements OutService {

    @Autowired
    private OutMapper outMapper;
    @Autowired
    private InvMapper invMapper;


    @Override
    public List<PickRespDTO> selectOrderByWhse(String whse) {
        List<PickRespDTO> orderByWhse = outMapper.getOrderByWhse(whse, 55);
        if(CollectionUtils.isEmpty(orderByWhse)){
            return null;
        }
        orderByWhse.forEach(item -> {
            item.setTitlePktCtrlNbr("合包号："+item.getPktCtrlNbr());
            item.setTitleCountSku("拣货数量："+item.getCountSku());
            item.setTitlePickMan("拣货人："+ (StringUtils.isEmpty(item.getPickMan())?"":item.getPickMan()));
        });
        return orderByWhse;
    }

    @Override
    public List<PickDetailRespDTO> selectPickDetail(String pktCtrlNbr, String whse) {
        return outMapper.getPickDetail(pktCtrlNbr,whse);
    }

    @Override
    public List<MyunitInv> getInvBySku(String whse, String sku) {
        return invMapper.getInvBySku(whse,sku);
    }

    @Override
    public int updatePicked(String sku, String pktCtrlNbr, String whse) {
        return outMapper.updatePicked(sku,pktCtrlNbr,whse);
    }

    @Override
    public int updatePickMan(String pickMan, String pktCtrlNbr, String whse) {
        return outMapper.updatePickMan(pickMan,pktCtrlNbr,whse);
    }
}